package l.l.w.leetcode.ImplementStrStr;

import com.sun.istack.internal.Pool;

/**
 * Created by llw on 2017/11/3.
 */
public class ImplementStrStr {
    public int strStr(String haystack, String needle) {
        if(haystack == null || needle == null || haystack.length() < needle.length()) return -1;
        if(haystack.equals(needle)) return 0;
        int result = -1;
        int j =0;
        for(int i = 0; i < haystack.length(); ++i){
            if(j == needle.length()){
                return i-j;
            }
            if(haystack.charAt(i) == needle.charAt(j)){
                j++;
            }else{
                i = i-j;
                j=0;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String a = "1234567890";
        String b = "4567";
        int result = new ImplementStrStr().strStr(a, b);
        System.out.println(result);
    }
}
